<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="../react18/react.development.js"></script>
    <script src="../react18/react-dom.development.js"></script>
    <script src="../react18/babel.min.js"></script>
  </head>
  <body>
    <div id="app"></div>
    <script type="text/babel">
      /*
        props的批量传递:
          - 我们可能会把一个对象的属性一个个的展开并传递到组件的内部,如果属性过多则可能会有些麻烦
          - 我们有两种批量传递的方式
            1. 可以直接把这个对象整体通过props传递进去,子组件自行展开接收(`<MySelf item={item} />`)
            2. 可以使用 扩展运算符+插值 的语法把对象的属性一个个展开传递进去(`<MySelf {...item} />`)
      */
      class MySelf extends React.Component {
        render() {
          console.log(this);
          const { name, age, sex } = this.props;
          //   const { name, age, sex } = this.props.item;

          return (
            <div>
              <h2>我的名字是:{name}</h2>
              <h2>我的年龄是:{age}</h2>
              <h2>我的性别是:{sex}</h2>
            </div>
          );
        }
      }

      class App extends React.Component {
        state = {
          students: [
            { id: 1, name: "张三", age: 18, sex: "男" },
            { id: 2, name: "李四", age: 20, sex: "女" },
            { id: 3, name: "王五", age: 12, sex: "女" },
          ],
        };
        render() {
          const { students } = this.state;
          return (
            <ul>
              {students.map((item) => {
                return (
                  <li key={item.id}>
                    <h2>下面是{item.name}的自我介绍</h2>
                    {/* <MySelf name={item.name} age={item.age} sex={item.sex} /> */}
                    {/* <MySelf item={item} /> */}
                    <MySelf {...item} />
                  </li>
                );
              })}
            </ul>
          );
        }
      }
      ReactDOM.createRoot(document.getElementById("app")).render(<App />);
    </script>
  </body>
</html>
